package com.org.khtn.command.delete;

import java.util.HashMap;
import java.util.Map;
import java.util.Observer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.org.khtn.command.MyParse;
import com.org.khtn.command.QueryPattern;
import com.org.khtn.command.select.Where;
import com.org.khtn.stringcommand.Format;

public class ParseDelete extends MyParse {
	String query;
	Map<Integer, String> data;
	public ParseDelete(String Query) {
		query = Query;
		
	}

	
	@Override
	public boolean eval() {
		Pattern a = Pattern.compile(QueryPattern.DELETE_PATTERN, Pattern.CASE_INSENSITIVE);
		Matcher b = a.matcher(query);

		return b.matches();

	}
	@Override
	public String[] parse ()
	{
		if (!eval())
			return null;
		Format f = new Format(query);
		query = f.XLC().toLowerCase();
	
	
		int idx = query.indexOf("where");
		int idx1 = query.indexOf(" ",	idx);
		String where = query.substring(idx1,query.length());
		String[] tt = query.split("\\s+");
		for (int i = 0 ; i <tt.length ; i++)
		{
			System.out.println(tt[i]);
			
		}
		String par[]= new String[2];
		if (query.contains("from"))
		{
			par[0] = tt[2];
		}
		else 
			par[0] = tt[1];
		if (idx==-1)
		{
			par[1] = null;
			return par;
		}
		par[1] = where.trim();
		return par;
	}
	public static void main(String[] args)
	{
		ParseDelete p =new ParseDelete("delete from aaa where   aa      = a    and bb  =  z         ");
		p.parse();
	}
}
